﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
namespace SQT.tracnghiem.Ajax.ASP.Game
{
    public partial class add_crossword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string request = Request.Form["request"];
            string[] split = request.Split(',');
            string name = split[0];
            int vertical = int.Parse(split[1]);
            int horizontal = int.Parse(split[2]);
            string primary_question = split[3];
            int primary_hor = int.Parse(split[4]);
            string[] ver_question = new string[vertical];
            string[] ver_word = new string[vertical*horizontal];

            int z = 0;
            for (int i = 5; i < 5+vertical; i++)
            {
                ver_question[z] = split[i];
                z++;
            }
            z = 0;
            for (int i = 5 + vertical; i < split.Length - 1; i++)
            {
                ver_word[z] = split[i];
                z++;
            }

            new TblCrossWordQuestionController().Insert(name, vertical, horizontal, primary_question,primary_hor);
            var get_last = new TblCrossWordQuestionController().FetchAll().Last();

            for(int i=0;i<vertical;i++)
            {
                string[] split2 = ver_question[i].Split('_');
                int ver = int.Parse(split2[0]);
                string ques = split2[1];
                new TblCrossWordDetailsQuestionController().Insert(get_last.Id, ver, ques);
            }

            for(int i=0;i<vertical*horizontal;i++)
            {
                string[] split2 = ver_word[i].Split('_');
                int ver = int.Parse(split2[0]);
                int hor = int.Parse(split2[1]);
                string word = split2[2];
                new TblCrossWordDetailsWordController().Insert(get_last.Id, ver, hor, word);
            }
        }
    }
}